package com.weblog.weblogapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.weblog.weblogapi.dao.mapper.ArticleTagMapper;
import com.weblog.weblogapi.dao.mapper.TagMapper;
import com.weblog.weblogapi.dao.pojo.ArticleTag;
import com.weblog.weblogapi.dao.pojo.Tag;
import com.weblog.weblogapi.service.TagService;
import com.weblog.weblogapi.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TagServiceImpl implements TagService {
    @Autowired
    private TagMapper tagMapper;
    @Autowired
    private ArticleTagMapper articleTagMapper;
    @Override
    public Result getAllTag() {
        List<Tag> tags = tagMapper.selectList(new LambdaQueryWrapper<>());
        return Result.success(tags);
    }

    @Override
    public List<Tag> findTagsByArticleId(int articleId) {
        List<Tag> tags = tagMapper.findTagsByArticleId(articleId);
        return tags;
    }

    @Override
    public Result deleteTag(int id) {
        int i=articleTagMapper.deleteById(id);
        return Result.success(null);
    }

    @Override
    public Result insertTag(ArticleTag articleTag) {
        int i=articleTagMapper.insert(articleTag);
        return Result.success(null);
    }
}
